package com.jiwei.community.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.jiwei.community.constants.SystemConstant;
import com.jiwei.community.dao.ReportMapper;
import com.jiwei.community.entity.Report;
import com.jiwei.community.enums.AppHttpCodeEnum;
import com.jiwei.community.service.ReportService;
import com.jiwei.community.vo.ResponseResult;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * (Report)表服务实现类
 *
 * @author 季伟
 * @since 2024-05-16 00:29:06
 */
@Service("reportService")
public class ReportServiceImpl extends ServiceImpl<ReportMapper, Report> implements ReportService {

    @Override
    public ResponseResult addReport(Long userId, Report report) {
        LambdaQueryWrapper<Report> queryWrapper = new LambdaQueryWrapper<>();
        queryWrapper.eq(Report::getCreateBy,userId);
        queryWrapper.eq(Report::getFromType,report.getFromType());
        queryWrapper.eq(Report::getFromId,report.getFromId());
        queryWrapper.eq(Report::getStatus, SystemConstant.REPORT_STATUS_NEED_VERIFY);
        List<Report> list = list(queryWrapper);
        if (list.size()>0)return ResponseResult.errorResult(AppHttpCodeEnum.FAILURE,"已举报该内容，等待审核");
        save(report);
        return ResponseResult.okResult();
    }
}

